package mul.Logic;

import java.util.ArrayList;

public class Level {

	private String level;//what level we are at now
	private int levelTime;
	private double spawningRate;
	private int speed;
	private ArrayList<ArrayList<Character>> crates = new ArrayList<ArrayList<Character>>(); 
	private int[] spawnProbabilities = new int[11]; 
	private int frostCrateProbability = 0;
	private int fireCrateProbability = 0;


	public Level(String levelName, int levelTime, double spawningRate, int speed) {
		this.level = levelName;
		this.levelTime = levelTime;
		this.spawningRate = spawningRate;
		this.speed = speed;
		
		for(int i = 0; i < 5; i++)
			crates.add(new ArrayList<Character>());
	}

	public void addCrate(int col, char c) {
		crates.get(col).add(c);
	}
	
	public ArrayList<Character> getColumn(int col) {
		return crates.get(col);
	}
	
	public int getLevelTime() {
		return levelTime;
	}

	public double getSpawningRate() {
		return spawningRate;
	}
	
	public String getName() {
		return level;
	}


	public int getSpeed() {
		return speed;
	}
	
	public void setSpawnProbability(int number, int probabilityPercentage) {
		spawnProbabilities[number] = probabilityPercentage;
	}
	
	public void setFrostCrateProbability(int probabilityPercentage) {
		frostCrateProbability = probabilityPercentage;
	}
	
	public void setFireCrateProbability(int probabilityPercentage) {
		fireCrateProbability = probabilityPercentage;
	}
	
	public int getFrostCrateProbability() {
		return frostCrateProbability;
	}
	
	public int getFireCrateProbability() {
		return fireCrateProbability;
	}

	public int getRandomCrate() {
		int randomPercentage = (int)(Math.random() * 100);
		int sum = 0;
		for(int i = 0; i < spawnProbabilities.length; i++)
			if(randomPercentage < sum+spawnProbabilities[i])
				return i;
			else
				sum += spawnProbabilities[i];
		
		System.err.println("LEVEL FAULT: PROBABILITIES DON'T ADD UP TO 100.");
		return -1;
	}

}
